﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Json;
using WorkSpace.UI.WorkSpaceRef;

namespace WorkSpace.UI.Windows
{
    public partial class CategoryWindow : ChildWindow
    {
        private Category _category;

        public CategoryWindow(Category category)
        {
            InitializeComponent();

            _category = category;
            this.DataContext = _category;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            WorkSpaceRef.WorkSpaceWebServiceSoapClient client = WorkSpaceModule.CreateWorkSpaceWebServiceProxy();
            client.SaveCategoryCompleted += new EventHandler<SaveCategoryCompletedEventArgs>(client_SaveCategoryCompleted);
            client.SaveCategoryAsync(_category);
        }

        void client_SaveCategoryCompleted(object sender, SaveCategoryCompletedEventArgs e)
        {
            if (e.Error == null && e.Result.IsSuccess)
            {
                this.DialogResult = true;
            }
            else
            {
                MessageBox.Show("添加失败!");
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

